﻿/********************************************************************************
** @ Date:2022/04/18
** @ Author: Gaojia
** @ Description:自定义操作轮盘控件
** @ Version:1.0.0
** @ Fun:
********************************************************************************/

#ifndef CPushButtenA_H
#define CPushButtenA_H

#include <QWidget>
#include <QMutex>

class CPushButtenA : public QWidget
{
	Q_OBJECT

public:
	CPushButtenA(QWidget *parent = nullptr);
	~CPushButtenA();
	void SetPushButtenText(QString sCenter);
	void SetPushButtenText(QString sCenter, QString sUp, QString sDown, QString sLeft, QString sRight);
	void setPushButtonsEnable(bool bState);//设置所有按钮状态

	void forbiddenAllOperateButtonA();//禁用所有操作按钮
	void enableAllOperateButtonA();//启用所有操作按钮

private:
	QMutex m_Mutex;
	QString m_sUp;
	QString m_sDown;
	QString m_sLeft;
	QString m_sRight;
	QString m_sCenter;

	bool m_bEnableUse;//是否允许使用

signals:
	void PressedUp();//按下上
	void PressedDown();//按下下
	void PressedLeft();//按下左
	void PressedRigth();//按下右

	void ReleasedUp();//松开上
	void ReleasedDown();//松开下
	void ReleasedLeft();//松开左
	void ReleasedRigth();//松开右

	void ClieckedCenter();//点击中间
	void ClieckedCenterR();//松开中间

	void selectColor(QString colorString);
protected:
	void paintEvent(QPaintEvent *event)override;

	void mousePressEvent(QMouseEvent *event)override;
	void mouseReleaseEvent(QMouseEvent* event)override;
private:
	bool isPointInCir(const QPoint &point, const QRect &rect);
	QRectF drawRect;//整个大圆的范围
	QPainterPath fanShaped[4];
	QRectF centerCircularRect;//中心圆按钮的范围
	QPainterPath gradientArc(double startAngle, double angleLength, double arcHeight);
	enum class pressBtnType //按下的是哪个按钮
	{
		up = 0,
		left,
		down,
		right,
		center,
		None
	};
	pressBtnType pressedBtn{ pressBtnType::None };
};

#endif